
<template>
  <div class="manage_page fillcontain">
    <fml-header></fml-header>
    <el-container>
      <el-aside :width="leftSet" class="fml-el-side">
        <el-menu
          unique-opened
          :collapse="isCollapse"
          style="min-height: 100%;border-right:none;padding-bottom:60px;"
          background-color="#184071"
          text-color="#EBF5FF"
          active-text-color="#fff"
          router
        >
          <el-menu-item
            class="ellipsis fml-el-index"
            :class="$route.path=='/main'?'is-active' :''"
            @click.native="handleSelect"
            index="/main"
          >
            <i class="iconfont icon-shouye"></i>
            <span slot="title">平台中心</span>
          </el-menu-item>
          <fml-nav-menu :navMenus="menuList"></fml-nav-menu>
        </el-menu>
      </el-aside>
      <div class="fml-main">
        <el-main :style="{left:leftSet}" class="fml-el-main">
          <el-breadcrumb separator="/" class="flex-1">
            <el-breadcrumb-item>
              <el-tooltip
                class="collapse-head-icon"
                effect="light"
                content="单击收缩菜单"
                placement="bottom"
              >
                <i class="el-icon-menu  " @click="collapseClick" ></i>
              </el-tooltip>
              <i class="el-icon-location-outline mr6" style="color:#0080FF"></i>
              <span
                style="color:#4E4E4E"
              >当前位置：{{$route.meta.name?$route.meta.parent+' / '+$route.meta.name:$route.meta.name}}</span>
            </el-breadcrumb-item>
          </el-breadcrumb>
          <router-view></router-view>
        </el-main>
      </div>
    </el-container>
  </div>
</template>
<script>
import fmlHeader from "../../components/header";
import fmlNavMenu from "../../components/navMenu";
import fetchService from "../../fmlService/fetchService";
export default {
  components: {
    fmlHeader,
    fmlNavMenu
  },
  data() {
    return {
      menuUrl: "",
      leftSet: "200px",
      defaultActive: "",
      isCollapse: false, //左侧菜单伸缩
      menuList: []
    };
  },
  methods: {
    //收缩
    collapseClick() {
      this.isCollapse = !this.isCollapse;
      this.leftSet = this.isCollapse ? "64px" : "200px";
      this.$store.commit("setCollapse", this.isCollapse);
    },
    // 菜单单击
    menuClick(url) {
      this.menuUrl = url;
    },
    // 平台中心
    handleSelect() {
      this.$router.replace({ path: "/main" });
    },
    // 权限按钮
    testHandler(test) {
      this.target = {};
      let child = [];
      test.map(item => {
        if (item.child == null) return;
        for (var i = 0; i < item.child.length; i++) {
          child.push(item.child[i].objectCode);
        }
        this.target={...this.target,...{[item.url]: child}};
        child = [];
      });
      sessionStorage.setItem('btnListTree',this.target)
      this.$store.commit('setBtnListTree',this.target)
    },
    // 菜单
    async menuTree() {
      let [err, res] = await fetchService.fetchGet({},'userPermission',false);
      if (err){
        this.$router.replace({ path: "/main" });
        this.$message({
          message: err.message || "菜单初始化失败",
          showClose: true,
          type: "error"
        });
        return
      }
      if (!res.data||res.data.length==0) {
        this.isLogining = false;
        this.$message({
          message: "暂无相关菜单访问权限",
          showClose: true,
          type: "waring"
        });
        this.$router.replace({ path: "/main" });
        return;
      }
      this.menuList=res.data
      let menuTree = [];
      res.data.map(item => {
        menuTree.push(item.url);
        if (item.child && item.child.length > 0) {
          item.child.map(child => {
            menuTree.push(child.url);
            if (child.child && child.child.length > 0) {
              child.child.map(childSub => {
                menuTree.push(childSub.url);
              });
            }
          });
        }
      });
      sessionStorage.setItem('menuTree',JSON.stringify(menuTree));
      this.$store.state.menuTree = menuTree;
      if (this.$route.params.url) {
        this.$router.push({ path: this.$route.params.url });
      }
      this.testHandler(res.data);
    }
  },
  mounted() {
    this.menuTree()
    this.$store.commit("setCollapse", false);
  }
};
</script>


<style lang="scss" >
.fml-el-side {
    position: fixed;
    height: 100%;
    left: 0;
    top: 61px;
    text-align: left;
    z-index: 11;
    box-shadow: inset 0px 3px 7px 0px rgba(0, 0, 0, 0.17);
  .el-menu-item i,
  .el-submenu__title i {
    font-size: 20px;
    margin-right: 16px;
    color: $iconColor;
  }
  .el-submenu__icon-arrow.el-icon-arrow-down {
    font-size: 15px;
  }

  .el-submenu .el-menu-item {
    overflow: hidden;
    text-overflow: ellipsis;
  }

    .fml-icon {
      margin-right: 16px;
    }
  .el-submenu,
  .el-menu-item {
    border-left: 4px solid transparent;
    cursor: pointer;
    -webkit-transition-property: boder-color;
    -webkit-transition-duration: 0.2s;
  }

  .el-menu-item.is-active {
    background-color: $mainActiveColor !important;
    border-color: $mainBorderColor;
  }
  .el-menu-item,
  .el-submenu__title {
    height: 50px !important;
    line-height: 50px !important;
    text-align: left;
  }
}
  .collapse-head-icon {
    cursor: pointer;
    padding-right: 20px;
    color: #00ac82;
  }
</style>
